﻿CREATE FUNCTION [dbo].[PurchaseBatch_Loans]
(	@BatchID int
)RETURNS TABLE
RETURN
SELECT     LoanID, UsixID, U, ContractHolder, ContractHolderID, DownPayment, DownPayment_Min, DownPaymentRatio, DownPaymentOK, Lamp_DP, 
                      AmountFinanced, AF_Adjusted, AFRatio_Max, AF_MaxByBookValue, SalesPrice, SellPriceRatio_Max, SellPrice_MaxByBookValue, LoanTerm, 
                      Term_Max, Lamp_Term, APR, APR_Min, APRFee, Lamp_APR, Payment, ModelAge, BookValue, MilesPerYear, MileagePerYear_Max, Lamp_Miles, Miles_Max, 
                      Overage, Overage_AF, Overage_SP, OverageFee, Fee, Advance, OverageFeeRatio, OverageAllowed, FeeRate, Fee_Max, PTI_Max, PTI, DTI_Max, DTI, 
                      OtherFeeName, OtherFeeValue, TotalDeductFee, RecourseMonths, AddMosRecourse, DeductFeeFromReserve, CheckToDealer, Reserve, GrossIncome,
                       NonEmploymentIncome, DebtNoCar, HousePayment, Installment, Revolving, JobTime_Min, JobTimeCurrent, ResidenceTime_Min, AreaTime_Min, 
                      MonthsCurrent, MonthsInArea, ModelAge_Max, LoanTermOK, APR_OK, MilesPerYearOK, DTI_OK, PTI_OK, ModelAgeOK, Lamp_DTI, Lamp_PTI, 
                      Lamp_ModelAge, Lamp_ResTime, Lamp_JobTime, ResidenceTimeOK, JobTimeOK, OpenUnitsAdjusted, OpenUnitsOK, Lamp_OpenUnits, StatusID, 
                      Status, OK, Lamp_OK, FirstName, LastName, ContactName, ContactPhone, ContactEmail, ContactFax, ContractHolderStreet, ContractHolderCity, 
                      ContractHolderState, ContractHolderZip, ContractHolderStateName, AgreementDay, TrackerReward, ServiceContract_Max, ServiceContract, 
                      ServiceContractOK, Lamp_ServiceContract, AF_Max, Overage_AF_Max, PurchaseBatchID
FROM         v_PurchaseContract AS PC
WHERE     (LoanID IN
                          (SELECT     LoanID
                            FROM          t_PurchaseBatch_Loans
                            WHERE      (BatchID = @BatchID)))




